//
//  loadBaseView.swift
//  swift一遍敲
//
//  Created by 刘耀宗 on 16/4/19.
//  Copyright © 2016年 刘耀宗. All rights reserved.
//

import UIKit
import SnapKit

class loadBaseView: UIView {
    weak var delegate: loadBaseViewDelegate?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor =  UIColor(white: 237 / 255, alpha: 1)
        prepareUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setNavigation()
    {
        
        
    
    
    }
    //变换
    func changeVC(imageName: String, labelText: String, choose: Bool)
    {
        self.textLael.text = labelText
        self.animaImageView.image = UIImage(named: imageName)
        if choose {
            imageViewForAnima.hidden = false
            coverView.hidden = false
        }
        
    
    
    }
    private func prepareUI()
    {
        addSubview( textLael)
        addSubview(animaImageView)
        addSubview(registerBtn)
        addSubview(loginBtn)
        addSubview(imageViewForAnima)
        addSubview(coverView)
        //图片约束
        animaImageView.snp_makeConstraints { (make) in
            make.width.equalTo(175)
            make.height.equalTo(175)
            make.center.equalTo(self)
        }
        //动画
        imageViewForAnima.snp_makeConstraints { (make) in
            make.edges.equalTo(animaImageView)
        }
        //遮罩
        coverView.snp_makeConstraints { (make) in
            make.edges.equalTo(imageViewForAnima)
        }
        
        //文字约束
        textLael.snp_makeConstraints { (make) in
            make.width.equalTo(200)
            make.top.equalTo(animaImageView.snp_bottom).offset(10)
            make.centerX.equalTo(self)
        }
        //注册按钮
        registerBtn.snp_makeConstraints { (make) in
            make.width.equalTo(80)
            make.height.equalTo(35)
          
            make.left.equalTo(self.snp_left).offset(50)
            make.top.equalTo(textLael.snp_bottom).offset(10)
        }
        //登录按钮
        loginBtn.snp_makeConstraints { (make) in
            make.size.equalTo(registerBtn)
            
            make.right.equalTo(self.snp_right).offset(-50)
            make.top.equalTo(textLael.snp_bottom).offset(10)
            
        }
        
    
    }
    //执行动画
    func startAnimation()
    {
        //创建动画
        let anima = CABasicAnimation(keyPath: "transform.rotation")
        anima.toValue = M_PI * 2
        anima.repeatCount = MAXFLOAT
        anima.duration = 20
        //要加上这一句,不然切换到其他控制器之后回来就会停止
        anima.removedOnCompletion = false
        
        imageViewForAnima.layer.addAnimation(anima, forKey: nil)
    
    
    }
    //遮罩
    private lazy var coverView: UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
        imageView.hidden = true
      
        return imageView
    
    
    
    }()
    
    //动画
    private lazy var imageViewForAnima: UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
        imageView.hidden = true
     
        
        return imageView
    
    
    }()
    
    //懒加载
    private lazy var textLael: UILabel = {
    let label = UILabel()
    label.font = UIFont.systemFontOfSize(15)
        //允许换行
        label.numberOfLines = 0
        label.text = "关注一些人,看看上面惊喜"
        //设置颜色
        label.textColor = UIColor.darkGrayColor()
        
        label.sizeToFit()
        //添加
    
        
        return label
    
    
    
    }()
    //动画
    private lazy var animaImageView: UIImageView = {
        let animaView = UIImageView(image: UIImage(named: "tabbar_message_center"))
  
        return animaView
        
    
    
    }()
    //注册按钮
    private lazy var registerBtn: UIButton = {
    let btn = UIButton()
        btn.setTitle("注册", forState: UIControlState.Normal)
        //设置标题颜色
        btn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Normal)
        //设置背景颜色
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        btn.sizeToFit()
        //添加单击事件
        btn.addTarget(self, action: #selector(loadBaseView.reginterClick), forControlEvents: UIControlEvents.TouchUpInside)
    
    return btn
    }()
    
    //登录按钮
    private lazy var loginBtn: UIButton = {
        let btn = UIButton()
        btn.setTitle("登录", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Normal)
        //设置背景图片
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
              btn.sizeToFit()
        btn.addTarget(self, action: #selector(loadBaseView.loginClick), forControlEvents: UIControlEvents.TouchUpInside)
        
        return btn
    }()
    //注册
    @objc private func reginterClick()
    {
    
            delegate?.reginBtn()
     
          
    }
    //登录
    @objc private func loginClick()
    {
        delegate?.loginBtn()
       
    
    }

}
protocol loadBaseViewDelegate: NSObjectProtocol {
    func reginBtn()
    func loginBtn()
}
